package com.z6school.manage.controller;

import com.z6school.manage.common.pojo.JsonResult;
import com.z6school.manage.common.pojo.PageObject;
import com.z6school.manage.mapper.ClassMapper;
import com.z6school.manage.po.Student;
import com.z6school.manage.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/student/")
@Controller
public class StudentController {

    @Autowired
    private StudentService studentService;

    @Autowired
    private ClassMapper classMapper;

    @ResponseBody
    @RequestMapping("findClassName")
    public String findClassName(Integer classId){
        String classname = classMapper.getClassNameById(classId);
        return classname;
    }

    @ResponseBody
    @RequestMapping("doFindPageObjects")
    public JsonResult doFindPageObjects(String studentName,Integer pageCurrent){
        PageObject<Student> page = studentService.findPageObjects(studentName, pageCurrent);
        System.out.println("controller"+page);
        return new JsonResult(page);
    }


    @RequestMapping("addStudentMessage")
    public String addStudentMessage(Student student){
        studentService.addStudentMessage(student);
        return "sys/student_edit";
    }

    @ResponseBody
    @RequestMapping("doDeleteObjects")
    public JsonResult doDeleteObjects(Integer...ids){
        studentService.doDeleteObjects(ids);
        return new JsonResult("delete ok");
    }

}
